package com.ruoyi.customer.mapper;

import com.ruoyi.customer.domain.CustomerSource;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

public interface CustomerSourceMapper {

    /**
     * 保存手机号+来源信息
     */
    @Insert("insert into custorm_tel_source_record(tel, source, flag, createBy, createTime) "
            + "values(#{tel}, #{source}, '0', #{createBy}, now())")
    void insertCustomerSource(CustomerSource customerSource);

    @Update("UPDATE t_customer a, ( SELECT GROUP_CONCAT( DISTINCT source order by createTime desc ) source, tel FROM custorm_tel_source_record GROUP BY tel ) b\n"
            + "set a.source = b.source where a.tel = b.tel and b.tel = #{tel}")
    void updateCustomerSource(@Param("tel") String tel);

    @Update("UPDATE total_comster a, ( SELECT GROUP_CONCAT( DISTINCT source order by createTime desc ) source, tel FROM custorm_tel_source_record GROUP BY tel ) b\n"
            + "set a.source = b.source where a.mobile = b.tel and b.tel = #{tel}")
    void updateTotalCustomerSource(@Param("tel") String tel);

}
